import { getAction } from "@/api/manage";
import mesPeProcessApi from "@/api/mesPeProcess";
export default {
    data() {
        return {
            topForm: {
                lineno: "", //线体
                lineName: '',//线体名称
                stationCode: "", //工站
                stationName: "", //工站名称
            },
            processTree: [],
            lines: [],
            sacn: "",
            scan: '',
            order: 0
        }
    },
    computed: {
        stations() {
            const data = [];
            this.processTree.forEach((item) => {
                const children = [];
                item.children.forEach((child) => {
                    const items = [];
                    child.children.forEach((one) => {
                        items.push({
                            title: one.processmname,
                            value: one.processmcode,
                        });
                    });

                    children.push({
                        disabled: true,
                        title: child.processmname,
                        value: child.processmcode,
                        children: items,
                    });
                });
                data.push({
                    disabled: true,
                    title: item.processmname,
                    value: item.processmcode,
                    children,
                });
            });

            return data;
        },
    },
    mounted() {
        this.getStations();
        this.getLines();
    },
    methods: {
        path(url) {
            this.$router.push(url);
        },
        changeLine(val, option) {
            let item = this.lines.find(item => item.codeValue === val)
            this.topForm.lineName = item ? item.textValue : ""
        },
        changeHandler(val, label) {
            this.topForm.stationName = label[0];
        },
        getStations() {
            mesPeProcessApi.getProcesstree().then((res) => {
                this.processTree = res.data || [];
            });
        },
        getLines() {
            const params = {
                startDate: "2020-01-01 00:00:00",
                endDate: "2120-01-01 23:59:59",
            };
            getAction("/mes-manufacture/mfProcess/getFilter", params).then((res) => {
                this.lines = res.data.lines.filter((item) => item != null);
            });
        },
    },
}